<?php
  $iden = '';
  $total_receivable = 0;
?>
<div class="module_title">
  Receivables<br/> 
</div>

<table class="datagrid" style="width:500px;">
  <thead class="datagrid">
    <tr>
      <th>
        Invoice Date
      </th>
      <th>
        Invoice#
      </th>
      <th>
        Days Due
      </th>
      <th>
        Due Date
      </th>
      <th>
        Total Due
      </th>
    </tr>
  </thead>
  <tbody class="datagrid" style="height:auto;">
    <?php foreach($receivables as $receivable):?>
      <?php if($iden != $receivable['iden']):?>
        <?php if($iden != ''):?>
          <tr>
            <td style="text-align:right;" colspan="4">
              Total
            </td>
            <td style="text-align:right;">
              <?php echo number_format($total_receivable,2)?>
            </td>
          </tr>
        <?php endif;?>
        <?php 
          $iden = $receivable['iden'];
          $total_receivable = 0;
        ?>
        <tr>
          <td colspan="5">
            <?php echo $receivable['list_name'] ?>
          </td>
        </tr>
      <?php endif;?>
      <tr>
        <td>
          <?php echo $receivable['document_date'] ?>
        </td>
        <td>
          <?php echo InvoicePeer::getInvoiceId($receivable['iden2']) ?>
        </td>
        <td style="text-align:right;">
          <?php echo $receivable['days_due'] ?>
        </td>
        <td>
          <?php echo $receivable['due_date'] ?>
        </td>
        <td style="text-align:right;">
          <?php echo number_format($receivable['total'],2) ?>
          <?php $total_receivable += $receivable['total']; ?>
        </td>
      </tr>
    <?php endforeach;?>
    <tr>
      <td style="text-align:right;" colspan="4">
        Total
      </td>
      <td style="text-align:right;">
        <?php echo number_format($total_receivable,2)?>
      </td>
    </tr>
  </tbody>
</table>